package com.raphon.weibo;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends TabActivity {

	private TabHost tabHost;

	public RadioGroup mainbtGroup;

	Intent intent = null; // Reusable Intent for each tab

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		this.setContentView(R.layout.main);

		this.tabHost = super.getTabHost();

		creatTabspec_Home();
		creatTabspec_Message();
		creatTabspec_Info();
		creatTabspec_Search();
		creatTabspec_More();

		// this.setContentView(tabHost);
		tabHost.setCurrentTab(0);

		this.mainbtGroup = (RadioGroup) this.findViewById(R.id.main_radio);
		mainbtGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				// TODO Auto-generated method stub

				switch (checkedId) {
				case R.id.radio_button0:
					tabHost.setCurrentTabByTag("Home");
					break;
				case R.id.radio_button1:
					tabHost.setCurrentTabByTag("Message");
					break;
				case R.id.radio_button2:
					tabHost.setCurrentTabByTag("Info");
					break;
				case R.id.radio_button3:
					tabHost.setCurrentTabByTag("Search");
					break;
				case R.id.radio_button4:
					tabHost.setCurrentTabByTag("More");
					break;

				}
			}
		});
	}

	private void creatTabspec_Home() {
		intent = new Intent();
		intent.setClass(MainActivity.this, HomeActivity.class);

		TabSpec tabSpec_home = tabHost.newTabSpec("Home");
		tabSpec_home.setIndicator("Home");
		tabSpec_home.setContent(intent);

		tabHost.addTab(tabSpec_home);
	}

	private void creatTabspec_Message() {
		intent = new Intent();
		intent.setClass(MainActivity.this, MessageActivity.class);

		TabSpec tabSpec_message = tabHost.newTabSpec("Message");
		tabSpec_message.setIndicator("Message");
		tabSpec_message.setContent(intent);

		tabHost.addTab(tabSpec_message);
	}

	private void creatTabspec_Info() {
		intent = new Intent();
		intent.setClass(MainActivity.this, InfoActivity.class);

		TabSpec tabSpec_info = tabHost.newTabSpec("Info");
		tabSpec_info.setIndicator("Info");
		tabSpec_info.setContent(intent);

		tabHost.addTab(tabSpec_info);
	}

	private void creatTabspec_Search() {
		intent = new Intent();
		intent.setClass(MainActivity.this, SearchActivity.class);

		TabSpec tabSpec_search = tabHost.newTabSpec("Search");
		tabSpec_search.setIndicator("Search");
		tabSpec_search.setContent(intent);

		tabHost.addTab(tabSpec_search);
	}

	private void creatTabspec_More() {
		intent = new Intent();
		intent.setClass(MainActivity.this, MoreActivity.class);

		TabSpec tabSpec_more = tabHost.newTabSpec("More");
		tabSpec_more.setIndicator("More");
		tabSpec_more.setContent(intent);

		tabHost.addTab(tabSpec_more);
	}
}
